Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

434
Views
¿Cómo soluciono la advertencia "Se espera que devuelva un valor al final de la función de flecha"?

Todo funciona bien, pero tengo esta advertencia Expected to return a value at the end of arrow function array-callback-return . Intenté usar forEach en lugar de map , pero luego <CommentItem /> ni siquiera aparece. ¿Cómo puedo solucionar esto?

 return this.props.comments.map((comment) => { if (comment.hasComments === true) { return ( <div key={comment.id}> <CommentItem className="MainComment"/> {this.props.comments.map(commentReply => { if (commentReply.replyTo === comment.id) { return ( <CommentItem className="SubComment"/> ) // return } // if-statement }) // map-function } // map-function __begin </div> // comment.id ) // return

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Un map() crea una matriz, por lo que se espera un return para todas las rutas de código (if/elses).

Si no desea una matriz o devolver datos, use forEach en su lugar.

over 4 years ago · Santiago Trujillo Report

0

La advertencia indica que no está devolviendo algo al final de la función de flecha del mapa en todos los casos.

Un mejor enfoque de lo que está tratando de lograr es usar primero un .filter y luego un .map , como este:

 this.props.comments .filter(commentReply => commentReply.replyTo === comment.id) .map((commentReply, idx) => <CommentItem key={idx} className="SubComment"/>);
over 4 years ago · Santiago Trujillo Report

0

La forma más fácil solo si no necesita devolver algo, simplemente return null

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!